// pages/vehicle/chachediaodu_nav/jindu_search/jindu_search.js
const mybehavior = require("../../../../../behaviors/requests")
Page({
  behaviors: [mybehavior],

  /**
   * 页面的初始数据
   */
  data: {
    base_urlstr: "https://logisticsengineering.gree.com/order_system",
    activeName: [],
    popup_date_show: false,
    currentDate: new Date().getTime(),
    popup_date_show1: false,
    start_time_str: "",
    end_time_str: "",
    list: [
    ],
    popup_show0: false,
    options0: ["未接单", "已接单", "已完结"],
    creator_id: "",
    page_size: 5,
    page: 1,
    total: 0,
    page_all: 0,
    pickup_person_name: "",
    receiver: ""
  },
  // 分页
  onPageChange(e) {
    // console.log("xxx",e.detail.sonParam);
    let p = e.detail.sonParam
    this.setData({
      page: p,
    })
    this.getDataList()
  },
  // 条件查询
  searchBtn() {
    let t = []
    if (this.data.start_time_str) {
      t.push(this.data.start_time_str)

    }
    if (this.data.end_time_str) {
      t.push(this.data.end_time_str)

    }
    let url = this.data.base_urlstr + "/receive_statistic"
    let data = {
      receiver: this.data.receiver,
      receive_time: t,
    }
    this.post(url, data).then(res => {
      if (res.code == 20000) {
        let show_list = res.data

        this.setData({
          list: show_list,
          activeName:0
        })

      } else {
        this.setData({
          list: []
        })
        wx.showToast({
          title: res.msg,
          icon: "error"
        })
      }
    }).catch(err => {
      this.setData({
        list: []
      })
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })

  },
  // 获取数据
  getDataList() {
    let url = this.data.base_urlstr + "/receive_statistic"

    let data = {
      receiver: this.data.receiver,
      receive_time: this.data.receive_time,
    }
    this.post(url, data).then(res => {
      if (res.code == 20000) {
        let show_list = res.data

        this.setData({
          list: show_list,
        })

      } else {
        this.setData({
          list: []
        })
        wx.showToast({
          title: res.msg,
          icon: "error"
        })
      }
    }).catch(err => {
      this.setData({
        list: []
      })
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })
  },

  // 点击筛选状态输入框
  onClick0(event) {
    // event.detail 为当前输入的值
    // console.log(event.detail);
    this.setData({
      popup_show0: true
    })
  },
  // 选择筛选状态输入框关闭
  onClose0() {
    this.setData({ popup_show0: false });
  },
  // 确定筛选状态--弹出框关闭
  onChange0(event) {
    const { picker, value, index } = event.detail;
    this.setData({
      status: value,
      popup_show0: false,
    })
  },

  // 确定日期1输入框
  onDateConfirm(e) {
    this.setData({
      popup_date_show: false,
      start_time_str: this.formatDate1(new Date(e.detail)),
    });
  },
  // 日期1输入框关闭
  onDateClose() {
    this.setData({
      popup_date_show: false,
    });
  },
  // 点击输入框显示选择日期1
  onDateClick() {
    this.setData({
      popup_date_show: true,
    });
  },


  // 确定日期2输入框
  onDateConfirm1(e) {
    this.setData({
      popup_date_show1: false,
      end_time_str: this.formatDate1(new Date(e.detail)),
    });
  },
  // 日期2输入框关闭
  onDateClose1() {
    this.setData({
      popup_date_show1: false,
    });
  },
  // 开始点击输入框显示选择日期2
  onDateClick1() {
    this.setData({
      popup_date_show1: true,
    });
  },


  onChange(event) {
    this.setData({
      activeName: event.detail,
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // this.getDataList()
    // wx.showToast({
    //   title: '请选择查询时间',
    //   icon: 'none'
    // })
    this.setData({
      receiver: wx.getStorageSync('name'),
    })
    this.getDataList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})